//	头部导航栏
mui.plusReady(function() {
	get();
})
var leader = document.getElementsByClassName('lead');
var leaderspan = document.getElementsByClassName('leadspan');
var mspeed = document.getElementById('speed');
var bank = document.getElementById('bank');
var big = document.getElementById('big');
var nothing = document.getElementById('nothing');
var tnum = 1;
//顶部点击事件函数
function go(wnum, name) {
	leader[wnum].addEventListener('tap', function() {
		for(var i = 0; i < 2; i++) {
			leaderspan[i].className = 'leadspan';
			mspeed.style.display = 'none';
			bank.style.display = 'none';
			big.style.display = 'none';
			nothing.style.display = 'none';
		}
		leaderspan[wnum].className = 'leadspan active';
		name.style.display = 'block';
		tnum = wnum + 1;
//		get();
	});
}

go(0, big);
go(1, bank);
var twindow = document.getElementById('twindow');
var tcancel = document.getElementById('cancel');
//	,取消按钮
tcancel.addEventListener('tap', function() {
	twindow.style.display = 'none';
});
//	刷新按钮变色效果
refresh.addEventListener('touchstart', function() {
	refresh.style.background = '#D8D8D8'
});
refresh.addEventListener('touchend', function() {
	refresh.style.background = 'white';
	setTimeout(function() {
		refresh.style.display = 'none';
		get(2);
	}, 500)
});
//弹窗结束
var str='';
var count=0;
function get() {

	if(tnum == 1) {
		//			贷款记录
		$.ajax({
			type: 'get',
			url: httpAdress + '/api/borrow/record/getrecord',
			data: {
				'userid': localStorage.getItem("userid"),
				first:count
			},
			contentType: "application/json; charset=utf-8",
			dataType: 'jsonp',
			jsonp: "callback",
			jsonpCallback: "successCallback",
			success: function(data) {
										console.log(JSON.stringify(data));
										console.log(count+':'+localStorage.getItem("userid"))
				var mydata = data.data;
				//						console.log(mydata[0].logo);
				//				mui.toast(data.msg);
				for(var i=0;i<mydata.length; i++) {
					str += '<ul class="main">' +
						'<li class="list">' +
						'<img src="' + httpAdress + mydata[i].logo + '"/>' +
						'<span class="name">' + mydata[i].name + '</span>' +
						'<p>' +
						'<span>' + mydata[i].time + '</span>' +
						'</p>' +
						'</li>' +
						'<li class="list">' +
						'<div class="lis_block">' +
						'<span>金额</span><br />' +
						'<span>' + mydata[i].money + '￥</span>' +
						'</div>' +
						'<div class="lis_block">' +
						'<span>期限</span><br />' +
						'<span>' + mydata[i].term + '个月</span>' +
						'</div>' +
						'<div class="lis_block">' +
						'<span>利率</span><br />' +
						'<span>' + mydata[i].rate + '</span>' +
						'</div></li><li class="list">' +
						'<button id="mspeed_btn_tel" type="button" class="mui-btn mui-btn-yellow mspeed_btn_tel">申请咨询电话</button>' +
						'<a href="'+mydata[i].murl+'"><button id="mspeed_btn_way" type="button" class="mui-btn mui-btn-blue mspeed_btn_way">申请记录查询</button></a>' +
						'</li></ul>'
				}
				big.innerHTML = str+'<a id="addmore" style="display: inline-block;width: 100%;text-align: center; display: none;padding: 10px 0; display: none;">点击加载更多</a>';
                if(mydata.length<10){
                	document.getElementById("addmore").innerHTML='没有更多了'
                }
				if(str == '') {
					nothing.style.display = 'block';
				};
				document.getElementById('addmore').addEventListener('tap',function () {
        count=count+10;
        get();
})
				if(str !== '') {
					document.getElementById("addmore").style.display='block';
					var mspeedbtntel = document.getElementsByClassName('mspeed_btn_tel');
					var mspeedbtnway = document.getElementsByClassName('mspeed_btn_way');	
					for(var k =0; k<mspeedbtntel.length; k++) {

						mspeedbtntel[k].addEventListener('tap', function() {
							twindow.style.display = 'block';
						});
//						mspeedbtnway[k].addEventListener('tap', function() {
//								for(var j =0;j<(parseInt(count)+parseInt(mydata.length)); j++) {
//									if(this == mspeedbtnway[j]) {
//                                      window.location.href=mydata[j-count].murl;
//									}
//								}
//							});

					}
				}
			},
			error: function() {
				mui.toast('加载失败，刷新一下');
				plus.nativeUI.closeWaiting();
				refresh.style.display = 'block';
			}
		});

	};
}
get();